<template>
  <div class="setting-drawer" >
    <a-drawer
      width="300"
      placement="right"
      @close="onClose"
      :closable="false"
      :visible="visible">
      <div class="setting-drawer-index-content">

        <div :style="{ marginBottom: '24px' }">
          <h3 class="setting-drawer-index-title">整体风格设置</h3>

          <div class="setting-drawer-index-blockChecbox">
            <a-tooltip>
              <template slot="title">
                暗色菜单风格
              </template>
              <div class="setting-drawer-index-item" @click="handleMenuTheme('dark')">
                 <img src="@/assets/dark.png" alt="dark" />
                <div class="setting-drawer-index-selectIcon" v-if="settings.theme === 'dark'">
                  <a-icon type="check"/>
                </div>
              </div>
            </a-tooltip>

            <!-- <a-tooltip>
              <template slot="title">
                亮色菜单风格
              </template>
              <div class="setting-drawer-index-item" @click="handleMenuTheme('light')">
                <img src="@/assets/light.png" alt="light" />
                <div class="setting-drawer-index-selectIcon" v-if="settings.theme !== 'dark'">
                  <a-icon type="check"/>
                </div>
              </div>
            </a-tooltip> -->
          </div>
        </div>

        <div :style="{ marginBottom: '24px' }">
          <h3 class="setting-drawer-index-title">浅色主题</h3>

          <div style="height: 20px">
            <a-tooltip class="setting-drawer-theme-color-colorBlock" v-for="(item, index) in colorList" :key="index">
              <template slot="title">
                {{ item.key }}
              </template>
              <a-tag :color="item.color" @click="changeColor(item)">
                <a-icon type="check" v-if="item.color === settings.primaryColor"></a-icon>
              </a-tag>
            </a-tooltip>

          </div>
        
            <br/>
          <!-- <h3 class="setting-drawer-index-title">深色主题</h3>
          <div style="height: 20px">
            <a-tooltip class="setting-drawer-theme-color-colorBlock" v-for="(item, index) in darkColorList" :key="index">
              <template slot="title">
                {{ item.key }}
              </template>
              <a-tag :color="item.color" @click="changeColor(item)"> 
                <a-icon  type="check" v-if="item.color === settings.primaryColor"></a-icon>
              </a-tag>
            </a-tooltip>

          </div> -->
        </div>
       

        <div :style="{ marginBottom: '24px' }">
          <h3 class="setting-drawer-index-title">导航模式</h3>

          <div class="setting-drawer-index-blockChecbox">
            <a-tooltip>
              <template slot="title">
                侧边栏导航
              </template>
              <div class="setting-drawer-index-item" @click="handleLayout('sidemenu')">
                <img src="@/assets/dark.png" alt="sidemenu" />
                <div class="setting-drawer-index-selectIcon" v-if="settings.layout === 'sidemenu'">
                  <a-icon type="check"/>
                </div>
              </div>
            </a-tooltip>
            <!--
            <a-tooltip>
              <template slot="title">
                顶部栏导航
              </template>
              <div class="setting-drawer-index-item" @click="handleLayout('topmenu')">
                <img src="https://gw.alipayobjects.com/zos/rmsportal/KDNDBbriJhLwuqMoxcAr.svg" alt="topmenu">
                <div class="setting-drawer-index-selectIcon" v-if="settings.layout !== 'sidemenu'">
                  <a-icon type="check"/>
                </div>
              </div>
            </a-tooltip>
            -->
          </div>
          <!-- <div :style="{ marginTop: '24px' }">
            <a-list :split="false">
              
              <a-list-item>
                <a-switch slot="actions" size="small" :defaultChecked="settings.fixedHeader" @change="handleFixedHeader" />
                <a-list-item-meta>
                  <div  slot="title">固定 Header</div>
                </a-list-item-meta>
              </a-list-item>
            
              <a-list-item >
                <a-switch slot="actions" size="small" :disabled="(settings.layout === 'topmenu')" :defaultChecked="settings.fixSiderbar" @change="handleFixSiderbar" />
                <a-list-item-meta>
                  <div slot="title" :style="{ textDecoration: settings.layout === 'topmenu' ? 'line-through' : 'unset' }">固定侧边菜单</div>
                </a-list-item-meta>
              </a-list-item>
            </a-list>
          </div> -->
        </div>
      
      </div>
    </a-drawer>
  </div>
</template>

<script>

import { updateTheme,colorList,darkColorList } from './settingConfig'

export default {
  name:'SettingDrawer',
  components: {
   
  },
  mixins: [],
  data () {
    return {
      visible: false,
      colorList,
      darkColorList
    }
  },
  props:{
    settings:{
      type:Object,
      default:()=>{}
    }
  },
  methods:{
    showDrawer () {
      this.visible = true
    },
    onClose () {
      this.visible = false
    },
    changeColor (item) {
      if(this.settings.screenWeak){
        this.$message.warning("请先关闭大屏显示模式");
        return false
      }
      if (this.settings.primaryColor != item.color) {
            updateTheme(item)
      }
      this.$emit('change',{type:'primaryColor',value:item.color});
      this.$eventHub.$emit('updateTheme', item)
    },
  

    handleMenuTheme (theme) {
      this.$emit('change',{type:'navTheme',value:theme});
    },
    
    handleLayout(mode){
      if(this.settings.layout !== mode){
        this.$emit('change',{type:'layout',value:mode});
      }
    },
    handleFixedHeader (fixed) {
     this.$emit('change',{type:'fixedHeader',value:fixed});
    },
    
    handleFixSiderbar (fixed) {
      this.$emit('change',{type:'fixSiderbar',value:fixed});
    },
    onScreenWeak(fixed){
      let color = '#002242'
      if(!fixed){
        color =this.settings.primaryColor
      }
      updateTheme(color)
      this.$emit('change',{type:'screenWeak',value:fixed});
    }
  }
  
}
</script>

<style lang="less" scoped>
    h1, h2, h3, h4, h5, h6 {
        color: #000000 !important;
    }
  .setting-drawer-index-content {

    .setting-drawer-index-blockChecbox {
      display: flex;

      .setting-drawer-index-item {
        margin-right: 16px;
        position: relative;
        border-radius: 4px;
        cursor: pointer;

        img {
          width: 48px;
        }

        .setting-drawer-index-selectIcon {
          position: absolute;
          top: 0;
          right: 0;
          width: 100%;
          padding-top: 15px;
          padding-left: 24px;
          height: 100%;
          color: #1890ff;
          font-size: 14px;
          font-weight: 700;
        }
      }
    }
    .setting-drawer-theme-color-colorBlock {
      width: 20px;
      height: 20px;
      border-radius: 2px;
      float: left;
      cursor: pointer;
      margin-right: 8px;
      padding-left: 0px;
      padding-right: 0px;
      text-align: center;
      color: #fff;
      font-weight: 700;

      i {
        font-size: 14px;
      }
    }
  }

  .setting-drawer-index-handle {
    position: absolute;
    top: 240px;
   
    width: 48px;
    height: 48px;
    right: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    pointer-events: auto;
    z-index: 1001;
    text-align: center;
    font-size: 16px;
    border-radius: 4px 0 0 4px;

    i {
    
      font-size: 20px;
    }

    
   
  }

  ::v-deep .ant-drawer-content {
    background: #fafafa !important;
    background-clip: padding-box;
    border: 0;
    
  }
</style>
